<!DOCTYPE html>
<html lang="zh">
<head>
    <title>CMS - 派后台管理系统</title>
    {include file="public/header" /}
</head>
<body>
<div class="container-fluid p-t-15">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header"><h4>搜索</h4></div>
                <div class="card-body">
                    <form class="form-inline searchForm">
                        <div class="form-group">
                            <label for="name">文章名称</label>
                            <div class="input-group">
                                <div class="input-group">
                                    <input type="text" class="form-control" id="name" value="{$where['name']}" name="name" placeholder="请输入文章名称或者ID">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="status">状态</label>
                            <select name="status" id="status" class="form-control">
                                <option value="" {if $where.status === ""}selected{/if}>所有</option>
                                <option value="1" {if $where.status === "1"}selected{/if}>启用</option>
                                <option value="0" {if $where.status === "0"}selected{/if}>禁用</option>
                            </select>
                        </div>
                        <button type="submit" class="btn btn-success" style="margin: -10px 0 0 10px;" id="search">搜索</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-lg-12">
            <div class="card">
                <div class="card-toolbar clearfix">
                    <div class="toolbar-btn-action">
                        <a class="btn btn-primary m-r-5" href="#!" onclick="iframe.createIframe('添加文章','/admin/cms.cms_article/add')"><i class="mdi mdi-plus"></i> 新增</a>
                        <button id="btn_edit" type="button" class="btn btn-success m-r-5" onclick="isEnable('enable')">
                            <span class="mdi mdi-check" aria-hidden="true"></span>启用
                        </button>
                        <button id="btn_disable" type="button" class="btn btn-warning m-r-5" onclick="isEnable('disable')">
                            <span class="mdi mdi-block-helper" aria-hidden="true"></span>禁用
                        </button>
                        <button id="btn_delete" type="button" class="btn btn-danger" onclick="del2()">
                            <span class="mdi mdi-window-close" aria-hidden="true"></span>删除
                        </button>
                    </div>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th>
                                    <label class="lyear-checkbox checkbox-primary">
                                        <input type="checkbox" id="check-all"><span></span>
                                    </label>
                                </th>
                                <th>文章ID</th>
                                <th>文章名称</th>
                                <th>分类名称</th>
                                <th>作者</th>
                                <th>摘要</th>
                                <th>发布时间</th>
                                <th>阅读数</th>
                                <th>点赞数</th>
                                <th>排序</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td>
                                    <label class="lyear-checkbox checkbox-primary">
                                        <input type="checkbox" name="ids" value="{$vo.id}"><span></span>
                                    </label>
                                </td>
                                <td>{$vo.id}</td>
                                <td>{$vo.name}</td>
                                <td>{$vo.category.name}</td>
                                <td>{$vo.author}</td>
                                <td>{$vo.abstract}</td>
                                <td>{$vo.show_time|date='Y-m-d H:i:s'}</td>
                                <th>{$vo.view}</th>
                                <th>{$vo.like}</th>
                                <td>{$vo.rank}</td>
                                <td>{if $vo.status == 1 }正常{else/}禁用{/if}</td>
                                <td>
                                    <div class="btn-group">
                                        <a class="btn btn-xs btn-default" href="#!" title="编辑" data-toggle="tooltip" onclick="iframe.createIframe('编辑文章','/admin/cms.cms_article/edit?id={$vo.id}');"><i class="mdi mdi-pencil"></i></a>
                                        <a class="btn btn-xs btn-default" href="#!" title="删除" data-toggle="tooltip" onclick="del('{$vo.id}')"><i class="mdi mdi-window-close"></i></a>
                                    </div>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                    </div>
                    {$list|raw}
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
    $(function(){
        $('.search-bar .dropdown-menu a').click(function() {
            var field = $(this).data('field') || '';
            $('#search-field').val(field);
            $('#search-btn').html($(this).text() + ' <span class="caret"></span>');
        });
    });
    function del($id) {
        $.alert({
            title: '系统提示',
            content: '删除提醒',
            buttons: {
                confirm: {
                    text: '确认',
                    btnClass: 'btn-primary',
                    action: function(){
                        $.post(url="/admin/cms.cms_article/del",data={"id":$id},function (res) {
                            if (res.status == 200) {parent.lightyear.notify('删除成功', 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');location.reload()}
                            else parent.lightyear.notify('删除失败', 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
                        });
                    }
                },
                cancel: {
                    text: '取消'
                }
            }
        });
    }
    // 删除
    function del2() {
        var checkID = "";
        var selectedItem = $("input[name='ids']:checked");
        if (selectedItem == "") return lightyear.notify("没有选中项", 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
        for (var i = 0; i < selectedItem.length; i++) {
            checkID += selectedItem[i].value + ",";
        }
        if (checkID=="") return lightyear.notify("没有选中项", 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
        $.confirm({
            title: '重要提醒!',
            content: '选中项将全部被删除，请谨慎操作!' ,
            backgroundDismiss: true,
            buttons: {
                ok: {
                    text: '确认',
                    btnClass: 'btn-danger',
                    action: function () {
                        $.post("/admin/cms.cms_article/del",data={id:checkID},function (res) {
                            if (res.status == 200){ lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');location.reload();}
                            else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
                        })
                    }
                },
                cancel: {
                    text: '取消',
                    btnClass: 'btn-primary'
                }
            }
        });
    }

    // 批量启用或者禁用
    function isEnable(type) {
        var checkID = "";
        var selectedItem = $("input[name='ids']:checked");
        if (selectedItem == "") return lightyear.notify("没有选中项", 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
        for (var i = 0; i < selectedItem.length; i++) {
            checkID += selectedItem[i].value + ",";
        }
        if (checkID == "") return lightyear.notify("没有选中项", 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
        $.confirm({
            title: '重要提醒!',
            content: type == 'enable' ? '选中项将全部启用，请谨慎操作!' : '选中项将全部禁用，请谨慎操作!',
            backgroundDismiss: true,
            buttons: {
                ok: {
                    text: '确认',
                    btnClass: 'btn-danger',
                    action: function () {
                        if (type == 'enable') {
                            $.post("/admin/cms.cms_article/enabled", data = {id: checkID}, function (res) {
                                if (res.status == 200) {
                                    lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
                                    location.reload();
                                } else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');

                            })
                        } else {
                            $.post("/admin/cms.cms_article/disabled", data = {id: checkID}, function (res) {
                                if (res.status == 200) {
                                    lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
                                    location.reload();
                                } else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
                            })
                        }
                    }
                },
                cancel: {
                    text: '取消',
                    btnClass: 'btn-primary'
                }
            }
        });
    }
</script>
</body>
</html>